<?php
class AdminAction extends Action{
    private $manage = null;
    public function __construct() {
        parent::__construct();
        $this->manage = new ManageModel();
    }
    public function index() {
        if(isset($_SESSION['admin'])) {
            $this->tpl->display(SMARTY_ADMIN.'public/admin.html');
        } else {
            $this->redirect->succ('?a=admin&m=login');
        }

    }
    //后台初始页
    public function main() {
        $this->tpl->display(SMARTY_ADMIN.'public/main.html');
    }
    //登陆
    public function login() {
        if(isset($_POST['send'])) {
            if($this->manage->login()) {
                $login = $this->manage->findLogin();
                //改变登录次数和ip以及时间
                $this->manage->changeLoginInfo();
                $_SESSION['admin']['user'] = $login[0]->user;
                $_SESSION['admin']['level'] = $login[0]->level_name;
                $this->redirect->succ('?a=admin','登陆成功，欢迎回来...');
            }
        }
        if(!isset($_SESSION['admin'])) {
            $this->tpl->display(SMARTY_ADMIN.'public/login.html');
        } else {
            $this->redirect->succ('?a=admin');
        }
    }

    //退出
    public function logout() {
        unset($_SESSION['admin']);
        session_destroy();
        if(!isset($_SESSION['admin'])) $this->redirect->succ('?a=admin&m=login');
    }

    public function ajaxCheckCode() {
        $this->manage->ajaxCheckCode();
    }
}






?>